export const schema = {
    type: "page",
    title: "用户新帖",
    body: [
        {
            type: "nav",
            stacked: false,
            links: [
                {
                    label: "用户新帖",
                    to: "/feeling_tone/list?org_id=${org_id}"
                },
                {
                    visibleOn: 'acl.can("feeling_tone:comment")',
                    label: "回复消息",
                    to: "/feeling_tone/comments?org_id=${org_id}"
                },
                {
                    visibleOn: 'acl.can("feeling_tone:replies")',
                    label: "收到的回复",
                    to: "/feeling_tone/replies?org_id=${org_id}"
                }
            ]
        },

        {
            type: "wrapper",
            className: "b-l b-b b-r bg-white no-padder",

            body: [
                {
                    className: 'wrapper',
                    visibleOn: '!data.org_id && !acl.can("skip:select-org")',
                    type: 'tpl',
                    tpl: `<div class="alert alert-warning">请先选择一个机构</div>`
                },
                {
                    visibleOn: 'data.org_id || acl.can("skip:select-org")',
                    type: "crud",
                    className: 'bg-white',
                    api: "/api/feeling_tone?org_id=${org_id}&page=${page}&author=${author}&keywords=${keywords}&start_time=${start_time}&end_time=${end_time}",
                    panelClassName: "no-border no-shadow bg-white",
                    toolbarInline: true,
                    columnsTogglable: false,
                    filter: {
                        panelClassName: 'm-l m-r m-b-xs no-shadow b-b',
                        title: '',
                        submitText: '',
                        controls: [
                            [{
                                label: '发布人',
                                type: 'text',
                                labelClassName: 'w-xs',
                                placeholder: '用户名/手机号',
                                name: 'author'
                            },

                                {
                                    label: '团队/项目',
                                    labelClassName: 'p-l p-r',
                                    type: 'text',
                                    name: 'keywords'
                                }],

                            [{
                                label: '发布时间',
                                type: 'datetime',
                                labelClassName: 'w-xs',
                                name: 'start_time',
                                inputFormat: 'YYYY-MM-DD HH:mm:ss'
                            },

                                {
                                    label: '到',
                                    type: 'datetime',
                                    name: 'end_time',
                                    inputFormat: 'YYYY-MM-DD HH:mm:ss'
                                },
                                {
                                    type: 'submit',
                                    label: '搜索',
                                    primary: true
                                }]
                        ]
                    },
                    columns: [
                        {
                            label: "序号",
                            name: 'id'
                        },
                        {
                            label: "发布时间",
                            innerClassName: 'w-sm block',
                            name: "created_at"
                        },
                        {
                            label: "所属团队／项目",
                            type: 'tpl',
                            tpl: '<%= (data.type == 2 ? data.project && ("项目：" + data.project.name) : data.type == 3 ?  data.team && ("团队：" + data.team.name) : "") || ""%>'
                        },
                        {
                            label: "发布人",
                            type: 'tpl',
                            tpl: '${author.username}'
                        },
                        {
                            label: "联系电话",
                            type: 'tpl',
                            tpl: '${author.phone}'
                        },
                        {
                            label: '内容',
                            innerClassName: 'w',
                            type: 'tpl',
                            tpl: '${content|truncate:15}'
                        },
                        {
                            type: "image",
                            name: "photo",
                            label: "图片",
                            multiple: true,
                            imageWrapClassName: 'thumb-lg m-r-xs',
                            popOver: {
                                title: "",
                                body:
                                    '<div class="w-xx-xxl"><% data.photo && data.photo.map(function(src) { %><img class="w-full m-b-sm" src="<%= src %>" /><% }) %></div>'
                            }
                        },
                        {
                            label: '点赞数',
                            name: 'like_count'
                        },
                        {
                            label: '评论数',
                            name: 'comment_count',
                            visibleOn: 'acl.can("feeling_tone:comment")',
                            type: 'tpl',
                            tpl: '<a data-link="./comments?fid=${id}&org_id=${org_id}">${comment_count}</a>',
                        },
                        {
                            label: '评论数',
                            name: 'comment_count',
                            visibleOn: '!acl.can("feeling_tone:comment")',
                            type: 'tpl',
                            tpl: '<a data-link="./replies?fid=${id}&org_id=${org_id}">${comment_count}</a>',
                        },
                        {
                            type: 'operation',
                            label: '操作',
                            buttons: [
                                {
                                    type: 'button',
                                    label: '查看',
                                    level: 'info',
                                    actionType: 'dialog',
                                    dialog: {
                                        title: '',
                                        body: `
                                        <h4>内容详情</h4>
                                        <p><%= data.content %></p>
                                        <hr />
                                        <h4>帖子地址</h4>
                                        <div class="text-center">
                                            <img src="/qrcode?size=250&data=<%= encodeURIComponent(data.preview_url) %>" />
                                        </div>
                                        `
                                    }
                                },
                                {
                                    type: 'button',
                                    label: '删除',
                                    confirmText: '确定要删除吗？',
                                    actionType: 'ajax',
                                    visibleOn: 'acl.can("feeling_tone:delete")',
                                    api: 'delete:/api/feeling_tone/${id}'
                                },
                                {
                                    type: 'button',
                                    label: '评论',
                                    actionType: 'dialog',
                                    visibleOn: 'acl.can("feeling_tone:reply")',
                                    dialog: {
                                        title: '评论',
                                        data: {
                                            '&': '$$',
                                            'content': ''
                                        },
                                        body: {
                                            type: 'form',
                                            api: 'post:/api/feeling_tone/comment',
                                            controls: [
                                                {
                                                    type: 'hidden',
                                                    name: 'id'
                                                },
                                                {
                                                    type: 'textarea',
                                                    name: 'content',
                                                    label: false
                                                }
                                            ]
                                        }
                                    }
                                },
                            ]
                        }
                    ]
                }
            ]
        }
    ]
};
